﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using DocumentFormat.OpenXml.Wordprocessing;

namespace intelliEssay.Interop
{
    /// <summary>
    /// This class stores all Application Specific Default values, including Fonts, Indentations.
    /// </summary>
    internal static class ApplicationSpecificDefaults
    {
        /// <summary>
        /// 获取某个特定程序的缺省值
        /// <example>
        /// <code>
        ///     var FontSize = GetDefaultValueByAppName(HostApplications.MSOffice2010,"FontSize",null);
        ///     var isOK = FontSize.Ascii==tsk.DocumentStructure.LviPargraph[0].Ascii;
        ///     ...
        /// </code>
        /// </example>
        /// </summary>
        /// <param name="appName">The name of the application</param>
        /// <param name="propertyName">The name of the property, case sensitive</param>
        /// <param name="type">该参数用于区分不同命名空间相同名字的类，填入null则不考虑命名空间</param>
        /// <returns></returns>
        public static dynamic GetDefaultValueByAppName(HostApplications appName, string propertyName, Type type = null)
        {
            if (type == typeof(int)) return 0;
            switch (appName)
            {
                case HostApplications.MsOffice2010:
                    {
                        if (propertyName == "Bold")
                        {
                            Bold bold = new Bold();
                            bold.Val = new DocumentFormat.OpenXml.OnOffValue() { Value = false };
                            return bold;
                        }
                        if (propertyName == "Italic")
                        {
                            Italic italic = new Italic();
                            italic.Val = new DocumentFormat.OpenXml.OnOffValue() { Value = false };
                            return italic;
                        }
                        if (propertyName == "IsUnderline")
                        {
                            Underline underline = new Underline();
                            underline.Val = new DocumentFormat.OpenXml.EnumValue<UnderlineValues>() { Value = UnderlineValues.None };
                            return underline;
                        }
                        if (propertyName == "Color")
                        {
                            Color color = new Color();
                            color.Val = new DocumentFormat.OpenXml.StringValue() { Value = "auto" };
                            return color;
                        }
                        if (propertyName == "VerticalTextAlignment")
                        {
                            VerticalTextAlignment v = new VerticalTextAlignment() { Val = new DocumentFormat.OpenXml.EnumValue<VerticalPositionValues>() { Value = VerticalPositionValues.Baseline } };
                            return v;
                        }
                        if (propertyName == "CharacterScale")
                        {
                            CharacterScale cs = new CharacterScale() { Val = new DocumentFormat.OpenXml.IntegerValue() { Value = 0 } };
                            return cs;
                        }
                        if (propertyName == "Spacing")
                        {
                            return new Spacing() { Val = new DocumentFormat.OpenXml.Int32Value() { Value = 0 } };
                        }
                        if (propertyName == "FontFamily")
                        {
                            return new RunFonts()
                            {
                                Ascii = "Times New Roman",
                                AsciiTheme = null,
                                ComplexScript = "宋体",
                                ComplexScriptTheme = DocumentFormat.OpenXml.Wordprocessing.ThemeFontValues.MajorEastAsia,
                                EastAsia = "宋体",
                                EastAsiaTheme = null,
                                HighAnsi = "宋体",
                                HighAnsiTheme = DocumentFormat.OpenXml.Wordprocessing.ThemeFontValues.MajorEastAsia,
                                Hint = DocumentFormat.OpenXml.Wordprocessing.FontTypeHintValues.EastAsia
                            };
                        }
                        if (propertyName == "Indentation")
                        {
                            return new Indentation() { Left = "0", LeftChars = 0, Right = "0", RightChars = 0, FirstLine = "0", FirstLineChars = 0, Hanging = "0", HangingChars = 0 };
                        }
                        if (propertyName == "Justification")
                        {
                            return new Justification() { Val = JustificationValues.Left };
                        }
                        if (propertyName == "FontSize")
                        {
                            return new FontSize() { Val = "21" };
                        }
                        if (propertyName == "DefaultTabStop")
                        {
                            return new DefaultTabStop() { Val = 420 };
                        }
                        if (propertyName == "SpacingBetweenLines")
                        {
                            return new SpacingBetweenLines()
                            {
                                Before = "0",
                                After = "320",
                                BeforeLines = 0,
                                Line = "1.08",
                                AfterLines = 320
                            };
                        }
                    }
                    break;
                default: return null;
            }
            return null;
        }
    }
}